import ArrayUtil from '@/ArrayUtil';
import SelectUtil from '@/SelectUtil';
import EffectCommon from 'code/Core/Common/EffectCommon';
import MovementCommon from 'code/Core/Common/MovementCommon';
import UnitCommon from 'code/Core/Common/UnitCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 死亡飞斧
 **/
export default class BossSpell_DeathAxe extends AbilityBase {
    static instance: BossSpell_DeathAxe;
    constructor(id: string = 'Asm1') {
        super(id);
        BossSpell_DeathAxe.instance = this;
        this.init();
        se.onUnitSpellEffect(this.onSpellEffect.bind(this), this.id);
    }
    init() {}
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        BossAbilityManagerInstance.text('死亡飞斧', source);
        target = SelectUtil.getRandomEnemyInRange(source, 1000);
        let x = GetUnitX(target),
            y = GetUnitY(target);
        let mark = AddSpecialEffect(BossAbilityManagerInstance.SpellMark, x, y);
        MovementCommon.定点限高投射物({
            missile: 'Abilities\\Weapons\\Axe\\AxeMissile.mdl',
            tarX: x,
            tarY: y,
            caster: source,
            maxHeight: 400,
            speed: 600,
            other: mark,
            onReachTarget: this.onReach.bind(this),
        });
    }
    onReach(p: 定点限高投射物参数) {
        DestroyEffect(p.other);
        let es = SelectUtil.getEnemyUnitsInRange(p.caster, 175, p.curX, p.curY);
        let target = ArrayUtil.randomElement(es);
        if (target == null) return;
        let dmg = UnitCommon.取攻击(p.caster);
        DamageSystemInstance.applyAttackDamage(target, p.caster, dmg);
        es = SelectUtil.getEnemyUnitsInRange(p.caster, 550, p.curX, p.curY);
        ArrayUtil.removeElement(es, target);
        target = ArrayUtil.randomElement(es);
        if (target == null) return;
        EffectCommon.模拟弹射({
            missile: 'Abilities\\Weapons\\Axe\\AxeMissile.mdl',
            target,
            caster: p.caster,
            speed: 500,
            radian: 0.5,
            onHit: this.onHit.bind(this),
            bounceCount: 6,
            scale: 5,
        });
    }
    onHit(p: 弹射参数) {
        let dmg = UnitCommon.取攻击(p.caster);
        DamageSystemInstance.applyAttackDamage(p.target, p.caster, dmg);
    }
    onSpellEffect() {
        this.cast(GetSpellTargetX(), GetSpellTargetY(), GetTriggerUnit(), GetSpellTargetUnit());
    }
}
